/**
 * Created by DELL on 2017/5/23.
 */
//个人题库控制器
var appQues=angular.module('appTeacher',['ngResource','ngRoute','oc.lazyLoad','ngCookies']);
appQues.controller('quesCtr',function ($scope,callSerive,$resource,$cookieStore) {
    //创建页面提交数据对象
    $scope.userinfo=$cookieStore.get("loginInfo");
    $scope.username=$scope.userinfo.name;
    $scope.postData={
        empid:$scope.userinfo.empid,
        pageindex:1,
        loadtype:0
    };
    $scope.loginOut = function () {
        $cookieStore.remove("loginInfo");
        window.location.href = '../../../login.html';
    };
    $scope.subject=[];
    $scope.datacount=[];
    $scope.indexCount=null;
    $scope.subjectCount=null;
    //按我的资源默认排序
    $scope.getMy=function () {
        $scope.postData.loadtype=0;
        callSerive.setdata($resource,$scope.postData,getData.initial);
    };
    //按最新上传排序
    $scope.getNew=function () {
        $scope.postData.loadtype=1;
        callSerive.setdata($resource,$scope.postData,getData.initial);
    };
    //按浏览数量排序
    $scope.getRead=function () {
        $scope.postData.loadtype=2;
        callSerive.setdata($resource,$scope.postData,getData.initial);
    };
    //按难度排序
    $scope.getDiff=function () {
        $scope.postData.loadtype=3;
        callSerive.setdata($resource,$scope.postData,getData.initial);
    };
    //上一页
    $scope.up=function () {
        $scope.postData.pageindex+=1;
        callSerive.setdata($resource,$scope.postData,getData.initial);
    };
    //下一页
    $scope.down=function () {
        $scope.postData.pageindex-=1;
        callSerive.setdata($resource,$scope.postData,getData.initial);
    };
    //点击分页按钮切换页面
    $scope.paging=function (index) {
        $scope.postData.pageindex=index+1;
        callSerive.setdata($resource,$scope.postData,getData.initial);
    };
    $scope.del=function (id) {
        var deldata={
            Delid:id
        };
        callSerive.delData($resource,deldata,getData.deldata);
    };
    //创建与后台数据交换方法
    var getData= {
        initial:function (res) {
            $scope.datacount=[];
            for(var i=0;i<Math.ceil(res.dataCount/10);i++){
                $scope.datacount.push([i]);
            }
            $scope.subject=[];
            $scope.subjectCount=res.dataCount;
            $scope.subject=res.data;
            $scope.indexCount=Math.ceil($scope.datacount.length/10);
        },
        deldata:function(res){
            callSerive.setdata($resource,$scope.postData,getData.initial);
        }

    };
    callSerive.setdata($resource,$scope.postData,getData.initial);//获取数据

});